package com.mycompany.queryBuilder;

import com.mycompany.model.Provincia;
import com.mycompany.model.QUser;
import com.mycompany.model.Regione;
import com.mysema.query.jpa.JPQLQuery;
import com.mysema.query.types.Predicate;
import com.mysema.query.types.expr.BooleanExpression;



public class QueryBuilder {


	

	
	
	public static Predicate buildQuery(String [] values){
		
	QUser user = QUser.user;
	BooleanExpression genericBooleanExpression = null;
	BooleanExpression resultBooleanExpression = null;
	
	for(int i=0 ;i<values.length;i++){
		
		if(!values[i].equals("")){
			
			if(i==0)
				genericBooleanExpression = user.nome.contains(values[0].toString());
			else if(i==1)
				genericBooleanExpression = user.cognome.contains(values[1].toString());
			else if(i==2)
				genericBooleanExpression = user.codiceFiscale.contains(values[2].toString());
			else if(i==3)
				genericBooleanExpression = user.email.contains(values[3].toString());
			else if(i==4)
				genericBooleanExpression = user.indirizzo.comune.contains(values[4].toString());
			else if(i==5)
				genericBooleanExpression = user.indirizzo.regione.name.contains(values[5].toString());
			else if(i==6)
				genericBooleanExpression = user.indirizzo.provincia.nome.contains(values[6].toString());
			
		
			if(resultBooleanExpression == null)
				resultBooleanExpression = genericBooleanExpression;
			else
				resultBooleanExpression = resultBooleanExpression.and(genericBooleanExpression);
		}
		
	
		
	}
	
	return resultBooleanExpression;
		
		
	}
	
}
